package com.mikeli.javacourse.lesson7.datasource02;

import cn.hutool.json.JSONUtil;
import com.mikeli.javacourse.lesson7.datasource01.DataSourceContext;
import com.mikeli.javacourse.lesson7.datasource01.mapper.TestMapper;
import com.mikeli.javacourse.lesson7.datasource02.ds01mapper.TestMapper01;
import com.mikeli.javacourse.lesson7.datasource02.ds02mapper.TestMapper02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TestService {
    @Autowired
    TestMapper01 mapper01;
    @Autowired
    TestMapper02 mapper02;
   public void test01(){
        DataSourceContext.setDataSource("slave");
        List<Map<String, Object>> result = mapper02.get();
       System.out.println("slave -->");
        System.out.println(JSONUtil.toJsonStr(result));
    }
    public void test02(){
        DataSourceContext.setDataSource("master");
        List<Map<String, Object>> result = mapper01.get();
        System.out.println("master -->");
        System.out.println(JSONUtil.toJsonStr(result));
    }
}
